// ml:run = $bin < B-small-attempt2.in > b-small.out2
#include <iostream>
#include <algorithm>

using ll = long long;

int const maxn = 200;
ll const inf = (1ll) << 44;
ll r[maxn], b[maxn];
ll f[maxn];
ll ans;
int n;

ll calc(int i, int j)
{
    return std::min(r[i] ^ b[j], b[i] ^ r[j]);
}

int count_one(int x)
{
    int ret = 0;
    for (; x; x /= 2) ret += x & 1;
    return ret;
}

ll find(int status)
{
    if (f[status] < inf) return f[status];
    if (count_one(status) == 1) return f[status] = 0;

    auto ret = inf;
    for (int i = 0; i < n; i++) {
        if (!(status & (1 << i))) continue;
        for (int j = 0; j < n; j++) {
            if (i == j || !(status & (1 << j))) continue;
            auto tmp = calc(i, j);
            ret = std::min(ret, tmp + find(status ^ (1 << i)));
            ret = std::min(ret, tmp + find(status ^ (1 << j)));
        }
    }
    return f[status] = ret;
}

int main()
{
    int T; std::cin >> T;
    for (int ti = 1; ti <= T; ti++) {
        std::cout << "Case #" << ti << ": ";
        for (int i = 0; i < maxn; i++) f[i] = inf;
        ans = inf;

        std::cin >> n;
        for (int i = 0; i < n; i++) std::cin >> r[i];
        for (int i = 0; i < n; i++) std::cin >> b[i];
        std::cout << find((1 << n) - 1) << "\n";
    }
}

